/*
** Copyright (c) 2010 by Lorimark Solutions, LLC.
** All Rights Reserved.
** Send inquiries to: info@lorimarksolutions.com
**
*/

#include "lcd.h"
#include <packet.h>

/*************************************************************************/
/*************************************************************************/
/*************************************************************************/

#define CHIP_BIT 4

//#define BAR_WIDTH 10
#define BAR_WIDTH 4

void drawBar( uint8 bar, uint8 value, uint8 min, uint8 max )
{
  uint8 barBit[5];
  uint8 i, j, k, x;

  i=5;
  k=0;
  while( i-- )
  {
    j = 8;
    while( j-- )
    {
      if( value > k ) barBit[i] |=  (1 << j);
      else            barBit[i] &= ~(1 << j);
      if( max == k )  barBit[i] |=  (1 << j);
      if( min == k )  barBit[i] &= ~(1 << j);
      k++;
    }
  }

  if( bar & (1<<CHIP_BIT) )
  {
    chipSelect_lcd(1);
  }
  else
  {
    chipSelect_lcd(0);
  }

  // Loop through the vertical pages
  bar *= BAR_WIDTH;
//  bar += 0x20;

  for( i=0; i<5; i++ )
  {
    x = 0b10111000 + i + 3;

    wait_lcd(0);
    writeByte_lcd( 0b01000000 + (bar&0b00111111) );  // Set horizontal address to 0

    wait_lcd(0);
    writeByte_lcd( x );  // Set page address

    //
    // Loop through the horizontal sections
    //
    for( j=0; j<BAR_WIDTH-1; j++ )
    {
       wait_lcd(1);
       writeByte_lcd( barBit[i] );  // Turn pixels on or off
    }
  }
}



